package com.cloudcc.mobile.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.cloudcc.cloudframe.adapter.CommonAdapter;
import com.cloudcc.cloudframe.adapter.ViewHolder;
import com.cloudcc.mobile.R;
import com.cloudcc.mobile.entity.beau.BeauListFilterEntity.SearchFilter;
import com.cloudcc.mobile.entity.beau.BeauListFilterEntity.SearchFilter.FilterChild;
import com.litesuits.android.log.Log;

public class BeauFilterChildAdapter extends
		CommonAdapter<FilterChild> {
	private int mSelectPos;
	private OnSelectItemListener mOnSelectItemListener;

	public BeauFilterChildAdapter(Context mContext) {
		super(mContext);
	}

	@Override
	public void convert(ViewHolder holder, FilterChild t) {
		holder.setText(R.id.tv1, t.name);

		ImageView image = holder.getView(R.id.iv1);
		if (mSelectPos == holder.getPostion()) {
			Log.d("mSelectPos",
					"hahahahah" + mSelectPos + " " + holder.getPostion());
			image.setImageResource(R.drawable.added_item);
		} else {
			image.setImageDrawable(new ColorDrawable(Color.TRANSPARENT));
		}
		final int pos = holder.getPostion();
		final FilterChild tt = t;
		holder.getConvertView().setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				mSelectPos = pos;
				notifyDataSetChanged();
				if (mOnSelectItemListener != null) {
					mOnSelectItemListener.onSelectItem(pos, tt);
				}

			}
		});
	}

	@Override
	public int getLayoutId() {
		return R.layout.beau_list_filter_childitem;
	}

	public void setSelectItem(int pos) {
		this.mSelectPos = pos;
	}

	public int getSelectPost() {
		return mSelectPos;
	}

	public OnSelectItemListener getmOnSelectItemListener() {
		return mOnSelectItemListener;
	}

	public void setmOnSelectItemListener(
			OnSelectItemListener mOnSelectItemListener) {
		this.mOnSelectItemListener = mOnSelectItemListener;
	}

	public interface OnSelectItemListener {
		void onSelectItem(int pos, FilterChild t);
	}
}
